/* sodd.t SALES ORDER LINE DELETE TRIGGER                             */
/*Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                 */
/*All rights reserved worldwide.  This is an unpublished work.        */
/*V8:ConvertMode=NoConvert*/
/*********************************************************************/
/*  Program :sodd.t                                                  */
/*  Author  :Ben Holmes                                              */
/*  Date    :03/19/95                                                */
/*  !Description : sod_det DELETE trigger program                    */
/*          : In order to enhance this trigger to support additional */
/*          : interfaces, add a DO-END block similar to the one      */
/*          : used for the Warehousing Interface to (1) check for the*/
/*          : need to continue processing; (2) move the relevant     */
/*          : fields to an appropriate work area; and (3) call       */
/*          : one or more subprograms to continue processing.        */
/*          : This .t program should remain short, relying on        */
/*          : subprograms to perform most of the work.               */
/*********************************************************************/
/*                             MODIFY LOG                            */
/*********************************************************************/
/*Revision 8.5          Last Modified:  03/14/96 BY: BHolmes *J0FY*  */
/*Revision 8.5          Last Modified:  06/25/96 BY: BHolmes *J0M9*  */
/*Revision 8.5          Last Modified:  07/19/96 BY: fwy     *J0MB*  */
/*Revision 8.5          Last Modified:  07/27/96 BY: fwy     *J12B*  */
/*Revision 8.5          Last Modified:  01/07/97 BY: jpm     *J1DM*  */
/*Revision 9.1          Last Modified:  08/12/00 BY: *N0KN* myb       */
/*                                                                   */
/*                                                                   */
/*********************************************************************/

TRIGGER PROCEDURE FOR DELETE OF SOD_DET.

/*J12B  if not can-find(first whl_mstr where whl_mstr.whl_act no-lock) */
/*J12B  then leave. */
/*J12B  if sod_det.sod_qty_ord ge 0 then leave. */
/*J12B  if    abs(sod_det.sod_qty_ship) */
/*J12B     ge abs(sod_det.sod_qty_ord) then leave. */

    {mfdeclre.i }
    define new shared variable w-recid as recid.
    define new shared work-table wf_old_sod_det like sod_det.

    define variable w-file as character format "x(24)".


    /* Warehousing Interface processing */

    WI:
    do:

    /* If there is no active external warehouse that is flagged to
    receive sales order export transactions, then do not process */
/*J12B*/    if not can-find(first whl_mstr no-lock
/*J12B*/        where whl_mstr.whl_act and whl_mstr.whl_so_exp)
/*J12B*/    then leave WI.

    /* If the order quantity is positive, then do not process
    because the lad_det DELETE trigger processing will take care of it */
/*J12B*/    if sod_det.sod_qty_ord ge 0 then leave WI.

    /* If at least as much material was shipped/returned as ordered,
    then do not process because the external warehousing system will
    delete the line on its own without prompting from MFG/PRO */
/*J12B*/    if abs(sod_det.sod_qty_ship) ge abs(sod_det.sod_qty_ord)
/*J12B*/    then leave WI.

    /* Do not process if multi-DB and in central database */
/*J0MB*/    find si_mstr no-lock where si_site = sod_det.sod_site no-error.
/*J0MB*/    if global_db ne "" and si_mstr.si_db ne global_db then leave WI.

    /* Move key sod_det values to work table for subsequent processing */
        assign w-recid = recid(sod_det).
        create wf_old_sod_det.
        if recid(wf_old_sod_det)= -1 then .
        assign
            wf_old_sod_det.sod_nbr       = sod_det.sod_nbr
            wf_old_sod_det.sod_line      = sod_det.sod_line
            wf_old_sod_det.sod_site      = sod_det.sod_site
            wf_old_sod_det.sod_loc       = sod_det.sod_loc
/*J0M9*/    wf_old_sod_det.sod_qty_ord   = sod_det.sod_qty_ord.

    /* Call subprogram to create export transaction for warehouse */
        w-file = "wisodd.p".
/*J1DM*/ /* {gprun.i ""wisodd.p""} */
/*J1DM*/    {gprunmo.i &module="WI"
                       &program="wisodd.p"}

/*J12B*/end. /* WI */

	HK:
	do:
        if not can-find ( first dt_mstr where dt_table = "sod_det" and dt_type = "DEL" ) then leave HK.
        
        if not can-find ( first wf_old_sod_det ) then do:
            create wf_old_sod_det.
            if recid(wf_old_sod_det)= -1 then .
        end.
        
        buffer-copy sod_det to wf_old_sod_det no-error.

        for first dt_mstr no-lock where dt_table = "sod_det" and dt_type = "DEL" :
        
			run value(global_user_lang_dir + "hk/hktrigdel.p")
       			"wf_old_sod_det"		/*old buffer*/
       			""						/*new buffer*/
       			dt_table				/*table name*/
       			""						/*field name*/
       			dt_type					/*type*/
       			recid(sod_det)			/*key*/	
       			sod_det.sod_nbr			/*key1*/
       			sod_det.sod_line		/*key2*/
       			""						/*key3*/
       			""						/*key4*/
       			""						/*key5*/
       			""						/*key6*/
       			""						/*key7*/
       			""						/*key8*/
       			.
			
        end.
	end.
